<template>
  <q-layout>
    <q-layout-header ref="header">
      <xheader :title="title"></xheader>
    </q-layout-header>
    <q-page-container>
      <xscrollarea :scroll-height="scrollHeight">
        <q-page padding>
          <q-select
            v-model="planCode"
            float-label="待维修编码"
            filter
            :options="planCodeOptions" clearable
          />
          <div v-show="name!==''">
            <br>
            <q-card>
              <q-card-title>
                待维修设备信息
              </q-card-title>
              <q-card-main>
                <q-item>
                  <q-item-main>
                    <div class="row">
                      <div class="col"><p>设备名称：</p></div>
                      <div class="col"><p>{{name}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>设备编码：</p></div>
                      <div class="col"><p>{{facCode}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>车间：</p></div>
                      <div class="col"><p>{{bzName}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>设备责任人：</p></div>
                      <div class="col"><p>{{yhName}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>是否停机：</p></div>
                      <div class="col"><p>{{type}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>报修人：</p></div>
                      <div class="col"><p>{{bxName}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>报修时间：</p></div>
                      <div class="col"><p>{{bxTime}}</p></div>
                    </div>
                    <div class="row">
                      <div class="col"><p>报修说明：</p></div>
                      <div class="col"><p>{{bxRemark}}</p></div>
                    </div>
                  </q-item-main>
                </q-item>
              </q-card-main>
            </q-card>
            <q-card>
              <q-card-title>
                故障分析及处理
              </q-card-title>
              <q-card-main>
                <q-item>
                  <q-item-main>
                    <q-input float-label="责任单位" v-model="orgName" clearable/>
                    <q-input float-label="故障原因" v-model="gzTypes" type="textarea" clearable/>
                    <q-input float-label="处理方法" v-model="gzMethod" type="textarea" clearable/>
                    <q-input float-label="改善措施" v-model="measures" type="textarea" clearable/>
                    <q-input float-label="备注" v-model="gzRemark" type="textarea" clearable/>
                  </q-item-main>
                </q-item>
              </q-card-main>
            </q-card>
            <br>
            <q-btn label="提交" color="primary" class="full-width" @click="submit"/>
          </div>
        </q-page>
      </xscrollarea>
    </q-page-container>
  </q-layout>
</template>

<script>

  import Xheader from '../../components/xheader'
  import Xscrollarea from '../../components/xscrollarea'

  export default {
    name: 'equipment_repair',
    components: { Xscrollarea, Xheader },
    props: {
      title: {}
    },
    data: () => ({
      scrollHeight: 0,
      planCode: '',
      planCodeOptions: [],
      facCode: '',
      name: '',
      type: '',
      bxName: '',
      bxUserId: '',
      bxTime: '',
      bxRemark: '',
      bzName: '',
      yhName: '',
      orgName: '',
      gzTypes: '',
      gzMethod: '',
      measures: '',
      gzRemark: ''
    }),
    watch: {
      planCode () {
        this.getInfo()
      }
    },
    methods: {
      initPlanData () {
        this.axios.post(this.$conf.server + '/equipment/getEquipmentPlanRepairList', {}).then(res => {
          if (res.data.result) {
            for (let v of res.data.Repairs) {
              let label = v.CODE
              if (v.NAME !== null) {
                label += '-' + v.NAME
              }
              this.planCodeOptions.push({ value: v.CODE, label: label })
            }
          }
        })
      },
      getInfo () {
        this.data = []
        this.name = ''
        this.bzName = ''
        this.yhName = ''
        if (this.planCode !== '') {
          this.axios.post(this.$conf.server + '/equipment/loadCollectionCheck.html',
            this.$qs.stringify({ CODE: this.planCode })).then(res => {
            if (res.data.result) {
              let data = res.data.Maintenance[0]
              this.facCode = data.CODE
              this.name = data.NAME
              this.type = data.TYPES
              this.bxName = data.BZNAME
              this.bxUserId = data.BXUSERID
              this.bxTime = data.BXTIME
              this.bxRemark = data.REMARKS
              this.bzName = data.BXNAME
              this.yhName = data.YHNAME
            }
          })
        }
      },
      submit () {
        this.axios.post(this.$conf.server + '/equipment/saveEquipmentRepairation',
          this.$qs.stringify({
            Equipmenttype: 'repair',
            PLANCODE1: this.planCode,
            CODE1: this.facCode,
            gztypes1: this.gzTypes,
            method1: this.gzMethod,
            Measures1: this.measures,
            Remarks1: this.gzRemark,
            orgname1: this.orgName,
            bxuserids: this.bxUserId
          })).then(res => {
          if (res.data.results === 'false') {
            this.$parent.info('维修失败')
          } else {
            this.$parent.info('维修成功')
            this.planCode = ''
            this.facCode = ''
            this.name = ''
            this.type = ''
            this.bxName = ''
            this.bxUserId = ''
            this.bxTime = ''
            this.bxRemark = ''
            this.bzName = ''
            this.yhName = ''
            this.orgName = ''
            this.gzTypes = ''
            this.gzMethod = ''
            this.measures = ''
            this.gzRemark = ''
          }
        })
      }
    },
    mounted () {
      this.scrollHeight = this.$parent.webHeight - this.$refs.header.$el.clientHeight
    },
    created () {
      this.initPlanData()
    }
  }
</script>

<style scoped>

</style>
